﻿
using System.Collections.Generic;
using System.Windows.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MVVM_CAD.Model;

namespace WPF_CAD.Test.FigureDrawer
{
    /// <summary>
    /// FigureDrawerFixture Engloba los test de unidad referidos al Objeto encargado 
    /// de dibujar las figuras en el canvas
    /// </summary>
    [TestClass]
    public class FigureDrawerFixture
    {
        #region Additional test attributes

        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //

        #endregion

        /// <summary>
        /// FigureDrawer, encargado de dibujar figuras.
        /// *como dibujo, recibo una figura, un canvas y agrego la figura.
        /// *como lo pruebo? 
        ///     las figuras tienen una coleccion de puntos, entonces si tomo la cantidad hijos
        ///     que tiene el canvas antes de dibujar y despues, no solo tiene q ser mayor, sino que tambien
        ///     tiene que ser la suma.
        /// </summary>
        [TestMethod]
        public void DrawAFigure()
        {
            //Arrange
            var canvas = new Canvas();
            var mockFigure = new Mock<IFigure>();

            mockFigure.SetupGet(f => f.PointsCollection).Returns(new List<IPoint>
                                                                     {
                                                                         new CustomPoint(1, 0),
                                                                         new CustomPoint(1, 1),
                                                                         new CustomPoint(2, 2)
                                                                     });
            //Act
            var canvasChildrensBeforeDrawFigure = canvas.Children.Count;
            MVVM_CAD.Common.FigureDrawer.DrawFigure(canvas, mockFigure.Object);
            var canvasChildrensAfterDrawFigure = canvas.Children.Count;

            //Assert
            Assert.IsTrue(canvas.Children.Count > canvasChildrensBeforeDrawFigure);
            Assert.AreEqual(canvas.Children.Count, canvasChildrensAfterDrawFigure);
            Assert.AreEqual(canvasChildrensBeforeDrawFigure + canvasChildrensAfterDrawFigure, canvas.Children.Count);
        }
    }
}